import 'package:flutter/material.dart';
import 'package:schoollifedemo/business/welcome/viewmodel/welcome_page_viewmodel.dart';
import 'package:schoollifedemo/commonwidget/button_widget.dart';
import 'package:schoollifedemo/commonwidget/common_base_page.dart';
import 'package:schoollifedemo/commonwidget/text_widget_with_overflow.dart';
import 'package:schoollifedemo/localization/local_text.dart';

class WelcomePage extends BaseStatefulPage {
  const WelcomePage({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() {
    return _WelcomePageState();
  }
}

class _WelcomePageState extends BasePageState {
  bool isCheck = false;
  final WelcomePageViewModel _viewModel = WelcomePageViewModel();

  @override
  void initState() {
    _viewModel.init();
    super.initState();
  }

  @override
  void dispose() {
    _viewModel.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        width: MediaQuery.of(context).size.width,
        margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top),
        color: Colors.white,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.start,
          children: [
            Container(
              margin: const EdgeInsets.only(top: 100),
              child: const TextWidgetWithOverflow(
                '你我校园，与你同行',
                width: 280,
                paddingLeft: 20,
                paddingTop: 15,
                radius: 50,
                paddingBottom: 15,
                paddingRight: 20,
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 50, bottom: 50),
              width: 200,
              height: 200,
              child: Image.asset('assets/images/common/img_app_open.png'),
            ),
            SizedBox(
              height: 30,
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  Checkbox(
                    value: isCheck,
                    onChanged: (changeValue) {
                      isCheck = !isCheck;
                      setState(() {});
                    },
                    shape: const CircleBorder(),
                  ),
                  Row(
                    children: [
                      const Text(PrivacyLocalText.read),
                      GestureDetector(
                        onTap: () {
                          _viewModel.goToPrivacyPage(context);
                        },
                        child: const Text(
                          PrivacyLocalText.privacyPolicy,
                          style: TextStyle(color: Color(0xFF529FE8)),
                        ),
                      ),
                      const Text(PrivacyLocalText.andClick),
                      const Text(
                        PrivacyLocalText.agree,
                        style: TextStyle(color: Color(0xFF529FE8)),
                      ),
                      const Text(PrivacyLocalText.andContinue),
                    ],
                  ),
                ],
              ),
            ),
            Container(
              margin: const EdgeInsets.only(top: 10),
              child: Center(
                child: ButtonWidget(
                  width: 300,
                  height: 55,
                  radius: 12,
                  onButtonClick: isCheck
                      ? () {
                          // 跳转到登录页面，当前隐私页面关闭。并且记录当前app版本号
                          _viewModel.gotoLoginPage(context);
                          _viewModel.setAppVersion();
                        }
                      : null,
                  insideWidget: Stack(
                    children: [
                      Container(
                        margin: const EdgeInsets.only(right: 10),
                        child: const Center(
                          child: Text(
                            '下一步',
                            style: TextStyle(fontSize: 16),
                          ),
                        ),
                      ),
                      Container(
                        margin: const EdgeInsets.only(left: 90),
                        child: Center(
                          child: SizedBox(
                            width: 22,
                            height: 14,
                            child: Image.asset(
                                'assets/images/common/img_arrow_right.png'),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
